package com.qth.valet.common.enums;

import com.alibaba.fastjson2.JSON;
import com.qth.valet.entity.property.Commission;
import com.qth.valet.entity.property.Vip;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 配置
 */
@Slf4j
@Getter
public enum PropertyEnum {

    /** 提成比例 */
    COMMISSION("COMMISSION", Commission.class, new Commission().setDriver(0.85).setPlatform(0.05).setFather(0.1)),
    /** 会员价格 */
    VIP("VIP", Vip.class, new Vip().setYear(300000L).setMonth(30000L))
    ;

    private final String key;
    private final Class<?> clazz;
    private final Object defaultValue;

    PropertyEnum(String theKey, Class<?> clazz, Object defaultValue) {
        this.key = theKey;
        this.clazz = clazz;
        this.defaultValue = defaultValue;
    }

    public Object parse(String value) {
        try {
            return JSON.parseObject(value, clazz);
        } catch (Exception e) {
            log.error("参数key：{}解析失败：{}", key, e.getMessage(), e);
            return this.defaultValue;
        }
    }

}
